package cn.ddiancan.dm.controller;

import cn.ddiancan.dm.domain.DataMigrationDTO;
import cn.ddiancan.dm.domain.DataMigrationLogDTO;
import cn.ddiancan.dm.service.DataMigrationExecuteService;
import cn.ddiancan.dm.service.DataMigrationService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/task")
public class DataMigrationController {

    @Autowired
    private DataMigrationExecuteService dataMigrationExecuteService;

    @Autowired
    private DataMigrationService dataMigrationService;

    @PostMapping
    public String executeOperation(@RequestBody DataMigrationDTO dataMigrationDTO) throws Exception {
       return dataMigrationExecuteService.executeDataMigration(dataMigrationDTO);
    }

    @PostMapping("/log/list/{pageNum}/{pageSize}")
    public PageInfo<DataMigrationLogDTO> executeDataLog(@RequestBody DataMigrationLogDTO dataMigrationLogDTO, @PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) throws Exception {
        Page page = new Page(pageNum, pageSize);
        return dataMigrationService.logList(dataMigrationLogDTO,page);
    }
}
